from win32com.client import Dispatch
import time
import random
class OpDemo:

    def __init__(self):
        # 创建com对象
        self.op = op = Dispatch("op.opsoft.1");
        self.hwnd = 0;
        self.send_hwnd = 0;
        op.SetPath("C:\\Users\\Administrator\\Desktop\\houtai\\image\\");
        #全局资源的位置


    def test_qidong(self):
        # 输出插件版本号
        print("版本号", self.op.Ver())
        a = self.op.WinExec("D:\\BaiduNetdisk_7.4.2.2", 1)
        print("打开", a)

    def test_bkmode(self):
        # 绑定
        self.hwnd = self.op.FindWindowByProcess("notepad.exe", "", "记事本")
        print(self.hwnd)
        time.sleep(0)
        # hwnd = self.op.FindWindowEx(self.hwnd, "RenderWindow", "TheRender");
        # print("找到子窗体", hwnd);
        # # time.sleep(0.1);
        #
        print("开始绑定")
        r = self.op.BindWindow(self.hwnd, "normal", "windows", "windows", 1)
        print("绑定结果：", r)
        # # opengl 后台模式 normal 前台模式;
        # if r == 0:
        #     print("绑定失败");
        # else:
        #     print("绑定成功,,,,");
        #     time.sleep(0);

    def test_windos(self):
        op_ret = self.op.GetWindowRect(self.hwnd)
        print(op_ret);
        self.op.SetClientSize(self.hwnd,864,497);
        print("窗口设置为x=867，y=467")
        self.op.MoveWindow(self.hwnd, 0, 0);
        print("窗口移动成功10，10");
        self.op.SetWindowTransparent(self.hwnd,255); #0是隐藏窗口不占位置，完全透明
        #透明度设置
        print("设置透明度成功")

    def test_print(self):
        down = self.op.KeyDown(0x48)
        if down == 0:
            print("输入失败")
        else:
            print("输入成功")


if __name__ == '__main__':
    # 初始化
    demo = OpDemo()
    # 打开雷电的方法
    # demo.test_qidong()
    # 绑定窗体
    demo.test_bkmode()
    # 移动窗体
    demo.test_windos()
    # 模拟输入
    demo.test_print()
    # 截图
    # demo.test_jietu()
    # 等待1秒
    # time.sleep(1)
    # 测试点击
    # demo.test_dianji()
    # 释放函数
    # demo.test_end()
    # print("成功结束")
